<%--
  Created by IntelliJ IDEA.
  User: wwh
  Date: 2017/9/6
  Time: 11:38
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>学生简历</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" type="text/css" href="../../static/common/layui/css/layui.css" media="all">
    <link rel="stylesheet" type="text/css" href="../../static/common/global.css" media="all">
</head>
<body>
<div class="admin-main" id="Vue">
    <div v-show="show">
        <blockquote class="layui-elem-quote">
            <input type="file" id="CV" name="fileUp" lay-type="file" lay-title="上传简历" class="layui-upload-file">
            <span><span style="color: red">*</span>只允许上传PDF格式</span>
            <%--<a href="javascript:;" class="layui-btn layui-btn-small" @click="add">--%>
                <%--<i class="layui-icon">&#xe608;</i> 添加简历--%>
            <%--</a>--%>
        </blockquote>
        <fieldset class="layui-elem-field">
            <legend>简历列表</legend>
            <div class="layui-form">
                <table class="layui-table">
                    <thead>
                    <tr>
                        <th>简历名称</th>
                        <th>备注</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody id="content"></tbody>
                </table>
            </div>
        </fieldset>
        <div class="admin-table-page">
            <div id="paged" class="page">
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="tpl">
    {{# layui.each(d.data,function(index,item){ }}
    <tr>
        <td>{{ item.filename.split('/')[item.filename.split('/').length-1] || "-" }}</td>
        <td>
            {{# if(item.comment != null){ }}
            {{ item.comment }}
            {{# } }}
        </td>
        <td>
            <a href="javascript:;" target="_blank" data-id="{{item.id}}" data-opt="delete" class="layui-btn layui-btn-danger layui-btn-mini">删除</a>
            <a href="javascript:;" target="_blank" data-id="{{item.id}}" data-opt="rename" class="layui-btn layui-btn-mini">重命名</a>
            <a href="javascript:;" target="_blank" data-id="{{item.id}}" data-opt="updateComment" class="layui-btn layui-btn-normal layui-btn-mini">修改备注</a>
        </td>
    </tr>
    {{# }); }}
</script>
<script>
    var userId = ${sessionScope.currentUser.getId()};
    console.log(userId);
</script>
<script type="text/javascript" src="/static/common/jquery-3.2.1.js"></script>
<script type="text/javascript" src="/static/js/utils.js"></script>
<script type="text/javascript" src="../../static/common/layui/layui.js"></script>
<script src="../../static/common/axios.min.js"></script>
<script src="../../static/common/vue.min.js"></script>
<script>
    layui.config({
        base: '../../static/js/layuiModulesEX/'
    });
    layui.use(['paging','laytpl','form','upload'],function () {
        var $ = layui.jquery,
            paging = layui.paging(),
            layerTips = parent.layer === undefined ? layui.layer : parent.layer, //获取父窗口的layer对象
            layer = layui.layer, //获取当前窗口的layer对象
            laytpl = layui.laytpl,
            upload = layui.upload,
            form = layui.form();

        var vm = new Vue({
            el:'#Vue',
            data:{
                show:true,
                CV:{}
            },
            methods:{
            }
        });

        layui.upload({
            url:'/upload/addCv/'+userId,
            ext:'pdf',
            elem:"#CV",
            success:function (response) {
                console.log(response);
                if(response.success){
                    layer.msg("上传成功",{icon:1,time:1000});
                    paging.get();
                }
            },
            before:function (input) {
                console.log(input);
//                layer.msg("文件上传中");
                console.log(123);
            }
        });

        paging.init({
            url:'/cv/findByCondition',
            elem:"#content",
            params:{
                stid:userId
            },
            contentType : "application/json; charset=utf-8",
            type: 'POST',
            tempElem: '#tpl', //模块容器
            pageConfig: { //分页参数配置
                elem: 'paged', //分页容器
                pageSize:10 //分页大小
            },
            success:function () {
//                alert('渲染成功');
            },
            fail:function (msg) {
//                alert('获取数据失败');
            },
            complate:function () {
//                alert('处理完成');
                /**
                 * 绑定按钮
                 */
                $('#content').children('tr').each(function () {
                    var name = $(this).children('td:first-child')[0].innerText.split("/");
                    name = name[name.length-1].split(".")[0];
                    console.log(name);
                    var comment = $(this).children('td:eq(1)')[0].innerText;
                    var $that = $(this).children('td:last-child');
                    var id = $that.children('a[data-opt = rename]').data('id');
//                    console.log(id);

                    /**
                     * 删除按钮
                     */
                    $that.children('a[data-opt = delete]').on('click',function () {
                        layer.confirm("确认删除吗？",function () {
                            axios.get('/cv/delOne/'+id)
                                .then(function (response) {
                                    console.log(response);
                                    if(response.data.success) {
                                        layer.msg("删除成功");
                                        paging.get();
                                    }
                                })
                        });
                    });

                    /**
                     * 重命名按钮
                     */
                    $that.children('a[data-opt = rename]').on('click',function () {
                        console.log("重命名");
                        layer.prompt({
                            formType:2,
                            title:"重命名",
                            value:name,
                            area:['200px','50px']
                        },function (value,index,elem) {
                            console.log(value);
                            axios.get("/cv/reName/"+id+"/"+value)
                                .then(function (response) {
                                    console.log(response);
                                    if(response.data.success){
                                        layer.msg("修改成功",{icon:1});
                                        layer.close(index);
                                        paging.get();
                                    }
                                })
                                .catch(function (msg) {
                                    console.log(msg);
                                })
                        })
                    });

                    /**
                     * 修改备注
                     */
                    $that.children('a[data-opt = updateComment]').on('click',function () {
                        layer.prompt({
                            formType:2,
                            title:"修改备注",
                            value:comment,
                            area:['200px','50px']
                        },function (value,index,elem) {
                            console.log(value);
                            var data = {
                                id:id,
                                stid:userId,
                                filename:name,
                                comment:value
                            };
                            axios.post("/cv/modifyOneById",data)
                                .then(function (response) {
                                    console.log(response);
                                    if(response.data.success){
                                        layer.msg("修改成功",{icon:1});
                                        layer.close(index);
                                        paging.get();
                                    }
                                })
                                .catch(function (msg) {
                                    console.log(msg);
                                })
                        })
                    });
                });
            }
        });
        form.render();
    });
</script>
</body>
</html>
